let mongoose = require('../model/db.js');

// 个人信息

//后台登录用户信息
const userSchema = new mongoose.Schema({
    user: String,
    password: String,
    cid: {
        type: mongoose.Types.ObjectId,
        ref: 'identity' //关联身份表
    },
    cos: String, //头像
    Real_name: String, //真实姓名
    phone: String, //手机号
    static_time: String, //创建时间
})

//登录人员身份表
const identitySchema = new mongoose.Schema({
    identity_name: String, //身份名称
    identity_describe: String, //身份描述
    static_time: String, //创建时间
    Permissions: {
        type: [mongoose.Types.ObjectId], //关联权限表
        ref: 'Permissions' //关联权限表
    },
    static_time: String,//创建时间
})

//登录人员权限表
const PermissionsSchema = new mongoose.Schema({
    Permissions_name: String, //权限名称
    Permissions_url: String, //权限url
    Permissions_level: Number, //权限等级
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'Permissions' //关联Permissions表
    }
})



// 售后表
const After_sales_managementSchema = new mongoose.Schema({
    order_id: {
        type: mongoose.Types.ObjectId,
        ref: 'cart' //关联订单表
    },
    After_sales_state: String, //售后状态
    shop_name: String, //商品名称
    shop_price: String, //商品价格
    After_sales_type: String, //售后类型
    After_sales_type_cause: String, //售后原因
    The_amount_requested: String, //申请金额
    Problem_description: String, //问题描述
    Request_vouchers: String, //申请凭证
    Refund_amount: String, //退款金额
    Refund_Channels: String, //退款渠道
    Commission_Impact: String, //佣金影响
    Application_timeline: String, //申请时间
    Review_time: String, //审核时间
    Refund_time: String, //退款时间
    Audits: String, //审核
    zitidian: String, //自提点
    zitidiantype: String, //自提点类型
})



// 商品类型表
const typeSchema = new mongoose.Schema({
    type: String, //类型名称
    add_Time: Date, //添加时间
    commission: Number,//佣金
    item_type: Boolean, //是否为商品类型

})
//商品品牌
const brandSchema = new mongoose.Schema({
    name: String, //品牌名称
    Inglist_name: String, //英文名称
    statue: Boolean, //是否为品牌
    children: Array,//子类分类
})
//商品标签
const labelSchema = new mongoose.Schema({
    name: String, //标签名称
    statue: Boolean, //是否为标签
    Text: String, //标签描述
})
// 商品表
const shopSchema = new mongoose.Schema({
    name: String,//商品名称
    description: String,//商品描述
    price: Number,//价格
    discount: Number,//折扣
    //链接type表
    type: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'types'
    },//商品类型
    img: String,//商品图片
    detailsimg: Array,//商品详情图片
    limited: Number,//限购数量
    sell: Number,//已售数量
    shopid: String,//商品编号
    brand: String,//品牌  
    specification: String,//规格
    Production: String,//生产日期
    shelflife: String,//保质期
    storagemode: String,//储存方式
    inventory: Number,//库存
    label: String,//标签
    statue: String,//状态
})

//团长表
const groupSchema = new mongoose.Schema({
    name: String,//团长姓名
    phone: String,//联系方式
    pick_name: String,//自提点名称
    pick_address: String,//自提点地址
    pick_type: String,//自提点类型
    examine_name: String,//审核人
    examine_type: String,//审核状态
    examine_time: String,//审核时间
    void_text: String,//作废理由
    deal_price: Number,//成交金额
    daar_num: Number,//成交数量
    statue: String,//状态
    label: Array,//标签
    // -------
    wx_name: String,//授权微信昵称
    store_statue: String,//是否有门店
    coordinate: String,//坐标
    door_number: String,//门牌号
    start_time: String,//营业开始时间
    end_time: String,//营业结束时间
    business_img: String,//营业执照
    pick_img: String,//自提点图片
    phone_spare: String,//备用电话
    user_img: Array,//身份信息
})
// 购物车  //订单
const cartSchema = new mongoose.Schema({
    userid: {
        type: mongoose.Types.ObjectId,
        ref: 'shopUser'
    },//用户id
    goodsid: {
        type: mongoose.Types.ObjectId,
        ref: 'shop'
    },//商品id
    shopnum: Number,//商品数量
    state: Number,//商品状态
    buy_time: String,//添加时间  时间戳
    groupid: {
        type: mongoose.Types.ObjectId,
        ref: 'groups'
    },
    checked: Boolean,//是否选中
    commission: Number,//佣金
    commission_state: String,//佣金状态
    daozhangshijian: Date,//到账时间
    commission_tixian: String//提现方式
})

// 前端用户表
const shopUserSchema = new mongoose.Schema({
    name: String,//用户名
    password: String,//密码
    img: String,//头像
    coupon: Array,//优惠券
    address: Array,//收货地址
    phone: String,//手机号
    Time_of_registration: String,//注册时间
    nickname: String,//昵称
    sex: String,//性别
    order_list: Array,//订单列表
    region: String,//地区
    The_amount_spent: Number,//消费金额
    user_type: Boolean,//用户类型
    Identification_number: String,//身份证号
})
// 用户标签表
const userTagsSchema = new mongoose.Schema({
    name: String,//标签名称
    description: String,//描述
    color: String,//颜色
    tagstype: Boolean,//标签类型
})

//团长标签表 
const groupLabelSchema = new mongoose.Schema({
    name: String,//标签名称
    level: Number,//等级
    statue: String,//状态
    describe: String,//描述
    color: String,//颜色
})

// 搜索热词表
const searchSchema = new mongoose.Schema({
    name: String,//搜索名称
    sort: Number,//排序
    state: Boolean,//状态
    add_Time: Date,//添加时间
})
// 发货表
const shipmentschema = new mongoose.Schema({
    userid: {
        type: mongoose.Types.ObjectId,
        ref: 'shopUser'
    },//用户id
    goodsid: {
        type: mongoose.Types.ObjectId,
        ref: 'shop'
    },//商品id
    cart_id: {
        type: mongoose.Types.ObjectId,
        ref: 'cart'
    },
    groupid: {
        type: mongoose.Types.ObjectId,
        ref: 'groups'
    },
    yunshusiji: String,//运输司机,
    phone: String,//手机号
    carnum: String,//车牌号
    car_type: String,//发货状态
    shopnum: Number,//商品数量
})


const adsSchema = new mongoose.Schema({
    name: String,//广告名称
    location: String,//广告位置
    sort: Number,//排序
    state: Boolean,//状态
    type: String,//类型
    img: String,//广告图片
    count: Number,//点击次数
    add_Time: Date,//创建时间
})

const billSchema = new mongoose.Schema({
    billtype:Boolean,//账单类型
    After_sales_managementid:{
        type: mongoose.Types.ObjectId,
        ref: 'After_sales_management'
    },//售后管理id
    goodsid:{
        type: mongoose.Types.ObjectId,
        ref: 'cart'
    },//订单
    state:String,//状态
    remark:String,//备注
    groupsid:{
        type: mongoose.Types.ObjectId,
        ref: 'groups'
    }

})

const userModel = mongoose.model('user', userSchema); //后台用户登录信息
const identityModel = mongoose.model('identity', identitySchema); //后台用户身份表
const PermissionsModel = mongoose.model('Permissions', PermissionsSchema); //后台用户权限表
const shopModel = mongoose.model('shop', shopSchema, 'shop'); //商品信息
const typeModel = mongoose.model('types', typeSchema, 'types'); //商品类型
const brandModel = mongoose.model('brand', brandSchema, 'brand'); //商品品牌
const labelModel = mongoose.model('label', labelSchema, 'label'); //商品标签
const groupModel = mongoose.model('groups', groupSchema, 'groups'); //团长信息
const groupLabelModel = mongoose.model('groupLabel', groupLabelSchema); //团长标签表
const After_sales_managementModel = mongoose.model('After_sales_management', After_sales_managementSchema, 'After_sales_management'); //后台用户售后管理表
const cartModel = mongoose.model('cart', cartSchema, 'cart'); //商品
const shopUserModel = mongoose.model('shopUser', shopUserSchema, 'shopUser'); //前台用户信息
const shipmentModel = mongoose.model('shipment', shipmentschema, 'shipment'); //发货信息
const usertagsModel = mongoose.model('usertags', userTagsSchema, 'usertags'); //用户标签表

const searchModel = mongoose.model('search', searchSchema, 'search'); //热词搜索
const adsModel = mongoose.model('ads', adsSchema, 'ads'); //广告
const billModel = mongoose.model('bill', billSchema, 'bill'); //账单

module.exports = {
    userModel,
    shopModel,
    typeModel,
    identityModel,
    PermissionsModel,
    After_sales_managementModel,
    cartModel,
    shopUserModel,
    groupModel,
    groupLabelModel,
    shipmentModel,
    usertagsModel,
    searchModel,
    adsModel,
    brandModel,
    labelModel,
    billModel
};
